package logic

import (
	"context"
	"renting-demo/model/mysql"

	"renting-demo/user_srv/internal/svc"
	"renting-demo/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
	return &UserLoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// Todo:用户名登录
func (l *UserLoginLogic) UserLogin(in *user.UserLoginRequest) (*user.Response, error) {
	// todo: add your logic here and delete this line
	username := in.Username
	password := in.Password
	//todo:验证用户名密码是否正确
	res, err := mysql.UserLogin(mysql.User{
		Username: username,
		Password: password,
	})
	if err != nil {
		return nil, err
	}

	return &user.Response{
		UserID: int64(res.ID),
	}, nil
}
